<?php $this->renderPartial('../common/_header');?>
<div class="container my-container">
    <div class="row">
        <div class="col col-lg-3">
            <?php $this->renderPartial('//common/'.($this->user ? 'menu' : 'menu_guest'));?>
        </div>
        <div class="col col-lg-9">

            <div id="content-manager-phone">

                <div class="col col-lg-12">
                    <div class="page-header">
                        <h2>Danh sách SĐT</h2>
                    </div>

                    <div id="phone_list">
                        <?php $this->renderPartial('manage_phone_list', array('userPhones' => $this->user->userPhones))?>
                    </div>
                </div>   

                <div class="col col-lg-12">  

                    <div class="page-header">
                        <h3>Thêm SĐT</h3>
                    </div>
                    <?php $form=$this->beginWidget('CActiveForm', array(
                            'id'=>'add-phone-form',
                            'enableClientValidation'=>true,
                            'clientOptions'=>array(
                                'validateOnSubmit' => true,
                                'validateOnChange' => true,
                            ),
                            'enableAjaxValidation'=>false,
                            'htmlOptions' => array('class' => 'form-horizontal my-form')
                        )); ?>


                    <div class="row">
                        <div class="col col-lg-8">
                            <?php echo $form->textField($phoneModel,'phone',array('placeholder'=> $phoneModel->getAttributeLabel('phone'),'maxlength'=>255)); ?>
                            <?php echo $form->error($phoneModel,'phone');?>
                        </div>
                        <div class="col col-lg-4">
                            <button class="btn btn-primary" type="submit">
                                <i class="icon-plus"></i> Thêm
                            </button>  
                        </div>
                    </div> 

                    <?php $this->endWidget(); ?>
                </div>

            </div>
        </div>
    </div>

</div>

<script>
    $('input[name="is_main"]').live('change', function(){
        $.post('<?php echo $this->createUrl('/user/page/ajaxUpdatePhoneList')?>', {
            action: 'update_main', 
            phone_id: $(this).val()
            }, function(data){
                $('#phone_list').html(data);    
        });    
    }); 

    $('.phone_remove a').live('click', function(e){
        e.preventDefault();

        if(confirm('Bạn có chắc chắn muốn loại bỏ SĐT '+ $(this).attr('phone') + ' ?')){
            $.post('<?php echo $this->createUrl('/user/page/ajaxUpdatePhoneList')?>', {
                action: 'remove', 
                phone_id: $(this).attr('phone_id')
                }, function(data){
                    $('#phone_list').html(data);    
            });    
        }                                                                                                                                            
    });                                                                                                                                                 
</script>




 